<!DOCTYPE html>
<html lang="zh">
<head>
  <head>
  <meta charset="UTF-8">
  <title>AMZ Protocol's Nebula Wallet</title>
  <meta name="renderer" content="webkit" />
  <meta name="format-detection" content="telephone=no,email=no"/>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"/>
  <meta name="Language" content="zh-CN" />
  <meta name="Copyright" content="恐龙" />
  <meta name="Designer" content="恐龙" />
  <meta name="Publisher" content="恐龙" />
  <meta name="Distribution" content="Global" />
  <meta name="author"  content="恐龙" />
  <meta name="robots" content="index,follow" />
  <meta name="googlebot" content="index,follow,archive" />
  <link rel="stylesheet" href="./css/common.css">
  <link rel="stylesheet" href="./css/api.css">
</head>
</head>
<body>
  <header>
    <div>
      <a class="logo">
        <img src="./img/logo.png" alt=""><span>AMZ Protocol Nebulas Wallet</span>
        <a class="mailto" href="mailto:anmingzhe@me.com">联系邮箱anmingzhe@me.com</a>
      </a>
      <nav>
        <a href="./index.html">代币余额</a>
        <a class="active-nav" href="./api.html">开发者api</a>
        <a href="./create.html">创建代币</a>
        <a href="./send.html">代币转账</a>
        <a href="./check.html">交易查询</a>
        <a href="./creategive.html">新建空投</a>
        <a href="./give.html">领取空投</a>
        <a href="./address.html">短地址</a>
      </nav>
      <hr>
    </div>
  </header>
  <div class="body">
    <h1>AMZ协议API</h1>
    <p class="min-title">NAS Dapp开发者可在本站发行自己的代币</p>
    <p class="min-title">NAS Dapp开发者可以在自己的Dapp调用本站提供的APi来给用户提供代币交易,以及代币查询等服务</p>
    <p class="min-title">以下代码示例中 amzDappAddress 变量代表本合约地址</p>
    <div class="api-title-item">
      <div class="title">AMZ协议合约地址</div>
      <div class="value">n1zAKhRRAfwr7zqafBhvpMcKHoWpyKAcQ4d</div>
    </div>
    <div class="api-title-item">
      <div class="title">AMZ协议合约哈希</div>
      <div class="value">74a931bbe23c7c1abefb1f39bc8a800af68221e5f1b2eba99c50dbdb75ffaad3</div>
    </div>
    <hr>
    <div class="function">
      <h2>getUserInfo</h2>
      <div>获取用户AMZ协议用户信息(包含用户资产)</div>
      <p>参数</p>
      <div class="fn-argu">无</div>
      <p>用法</p>
      <pre>
        nebPay.simulateCall(amzDappAddress, "0", "getUserInfo", JSON.stringify([]), {
          listener: function(res) {
            if(res.result == '' && res.execute_err == 'contract check failed') {
                alert('合约检测失败，请检查浏览器钱包插件环境！');
                return;
            }
            var user = JSON.parse(JSON.parse(res.result));
            /* 
             * user.token 是用户amz协议代币资产数组
             * user.token 数组里面 每一个对象均有一个tokenName 和tokenNum属性
             * tokenName 为 代币名称
             * tokenNum 为代币数量
            */ 
          }
        })
      </pre>
    </div>
    <hr>
    <div class="function">
      <h2>transaction</h2>
      <div>用户AMZ协议账户下所有代币转账(不支持NAS,NAS非AMZ协议代币)</div>
      <p>参数</p>
      <ul>
        <li><span>tokenName</span><span>要转账的代币名称(英文大写)</span></li>
        <li><span>to</span><span>接受代币的地址(NAS钱包地址)</span></li>
        <li><span>num</span><span>转账的代币数量</span></li>
        <li><span>hash</span><span>本次交易的哈希,交易成功需要给用户展示哈希 哈希开发者自己生成</span></li>
      </ul>
      <p>hash生成方法</p>
      <div>var hash = 'amz_hash' + Date.now() + ~~(Math.random() * 1e6)</div>
      <p>用法</p>
      <pre>
        nebPay.call(amzDappAddress, "0", "transaction", JSON.stringify([tokenName, to, num, hash]), { 
          listener: function(res) {
            alert(res.txhash ? '转账成功' : '转账失败！！！');
          }
        })
      </pre>
    </div>
    <div class="hr">**************************分割线**************************</div>
    <h1>短地址api</h1>
    <p class="min-title">以下代码示例中 nameAddress 变量代表本合约地址</p>
    <hr>
    <div class="api-title-item">
      <div class="title">短地址合约地址</div>
      <div class="value">n1j1STm7RCfxSPSdvu5ZHotfMUEZP8Ctchb</div>
    </div>
    <div class="api-title-item">
      <div class="title">短地址合约哈希</div>
      <div class="value">850c07dd129dcbeb40b28ec47b92a4fd6d833c31848ff1d2234d8de5c8556cb0</div>
    </div>
    <div class="function">
      <h2>getAll</h2>
      <p>参数</p>
      <div class="fn-argu">无</div>
      <p>用法</p>
      <pre>
        var nameArr = null;
        nebPay.simulateCall(nameAddress, "0", "getAll", JSON.stringify([]), {
          listener: function(res) {
            if(res.result == '' && res.execute_err == 'contract check failed') {
                toast('合约检测失败，请检查浏览器钱包插件环境！');
                return;
            }
            var info = res.result && JSON.parse(JSON.parse(res.result));
            if (info) {
              nameArr = info;
            }
          }
        })

        function name (address, type) {
          if (nameArr && nameArr.length) {
            for (var i = 0; i < nameArr.length; i++) {
              if (nameArr[i].address == add || nameArr[i].name == add) {
                return type ? nameArr[i].address : nameArr[i].name
              }
            }
          }

          return address
        }

        知道短地址 获取主网地址 如果没有获取到则返回传入的第一个值
        console.log(name('星云邮箱官方', true)) // n1X7NJbKyVz5wAsvaupBYt52fS76d38sStc
        知道主网地址获取短地址 如果没有短地址则返回 主网地址
        console.log(name('n1X7NJbKyVz5wAsvaupBYt52fS76d38sStc')) // 星云邮箱官方
      </pre>
    </div>
  </div>
  <script src="./js/jquery.js"></script>
  <script src="./js/nebPay.js"></script>
  <script src="./js/common.js"></script>
  <script src="./js/api.js"></script>
</body>
</html>